package com.abc.robot01.activity.compose

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.BasicText
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.abc.robot01.activity.mysp
import com.abc.robot01.activity.px

class DropdownDemo01 : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            var isSelected =  remember { mutableStateOf(false) }
            val scrollState = rememberScrollState()
            Column(
                modifier = Modifier
                    .verticalScroll(scrollState)
                    .fillMaxSize()
            ) {
//                Button(onClick = { /*TODO*/ }) {
//                    Text(text = "你好")
//                }
//                TwoStateButtonExample1(isSelected,"简约")
//                DropdownDemo()
                Spacer(modifier = Modifier.height(2.dp))
//                TwoStateButtonExample1(isSelected,"现代")
//                FilterChipExample()
                Spacer(modifier = Modifier.height(2.dp))
                Spacer(modifier = Modifier.height(2.dp))
                Spacer(modifier = Modifier.height(2.dp))
            }
        }
    }
}

@Composable
fun MyDropdownMenu(
    expanded: MutableState<Boolean>,
    selected: MutableState<String>,
    items: List<String>,
    ) {
    var selectedIndex by remember { mutableStateOf(0) }
    Box(modifier = Modifier.wrapContentSize().wrapContentSize(Alignment.TopStart).offset(
        x=30.px,
        y=150.px
    )) {
        DropdownMenu(
            expanded = expanded.value,
            onDismissRequest = { expanded.value = false },
            modifier = Modifier.width(374.px).background(
                Color.White)
        ) {
            items.forEachIndexed { index, s ->
                DropdownMenuItem(
                    modifier = Modifier.size(374.px,50.px),
                    onClick = {
                    selectedIndex = index
                    expanded.value = false
                } ,text={
                    BasicText(
                        modifier = Modifier
                            .clickable {
                                expanded.value = false
                                selected.value = s
                            }.offset(x=0.px),
                        text = s,
                        style = TextStyle(
                            fontWeight = FontWeight.Normal,
                            textAlign = TextAlign.Start,
                            fontSize = 26.mysp,
                            color = Color.Black,
                        ),
                    )
                })
            }
        }
    }
}


